/*--------------------------------------------------------------------------------------*\
**
** adv_ferry.cpp
**
** Heroes IV
** Copyright 2000, The 3DO Company
**
\*--------------------------------------------------------------------------------------*/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "adventure_events_set_action.h"

#include "adventure_map.h"
#include "adventure_object.h"
#include "adventure_object_ptr.h"
#include "adv_actor_action.h"
#include "actor.h"
#include "army.h"
#include "compressed_filter.h"
#include "game_time.h"

#include "saved_game_header.h"

namespace 
{
	const int k_memory_event_buffer_size	= 0;
	const int k_event_lifespan				= 50;			//in mili-seconds
};

t_adventure_event_set_action::t_adventure_event_set_action ( ) 
: t_adventure_event_base ( k_set_action_event ) 
{
	m_action_state	= k_adv_actor_action_wait;
}

t_adventure_event_set_action::t_adventure_event_set_action ( t_actor* army, t_adv_actor_action_id action_state ) 
: t_adventure_event_base ( k_set_action_event ) 
{ 
	m_global_id		= army->get_global_id();
	m_action_state	= action_state;
}

void t_adventure_event_set_action::execute_event( t_adventure_map* map, t_saved_game_header const & header ) 
{
	t_adventure_object * object = map->get_adventure_object_with_gid ( m_global_id );
	
	t_army* army = dynamic_cast<t_army*>(object);
	
	if (army == NULL) 
		return;
	
	army->set_action(m_action_state);

	m_time_end = get_time() + k_event_lifespan;

	return;
}

void t_adventure_event_set_action::undo_event( t_adventure_map* map , t_saved_game_header const & header )
{	
	return;
}

bool t_adventure_event_set_action::read( std::streambuf & buffer , int version )
{
	m_action_state = get<t_adv_actor_action_id> (buffer);

	return t_adventure_event_base::read( buffer , version );
}

bool t_adventure_event_set_action::write( std::streambuf & buffer )
{
	put<t_adv_actor_action_id> (buffer, m_action_state);

	return t_adventure_event_base::write( buffer );
}
